package com.etime.shycourse.controller.wx.applets.controller;

import com.etime.shy.common.PojoMessage;
import com.etime.shycourse.orde.services.interfaces.WxOrdersServices;
import com.etime.shycourse.wx.applets.dto.CourseDetailsDto;
import com.etime.shycourse.wx.applets.dto.UserTeacherDto;
import com.etime.shycourse.wx.applets.pojo.Lesson;
import com.etime.shycourse.wx.applets.pojo.Orders;
import com.etime.shycourse.wx.applets.services.interfaces.WxCourseDetailsServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName : WxCourseDetailsController  //类名
 * @Description : 微信小程序 的课时详细  //描述
 * @Author : W //作者
 * @Date: 2022/1/4  10:39
 */
@Api(tags = "微信课程详情数据接口")
@RestController
@RequestMapping("/wx/applets")
public class WXCourseDetailsController {
    @Autowired
    private WxCourseDetailsServices service;
    @Autowired
    WxOrdersServices wxOrdersServices;


    @ApiOperation("根据课程信息中的教师id(courseTeacherId)-> 查询出教师信息")
    @GetMapping("/courseTeacher/get/Teacher/{courseTeacherId}")
    public PojoMessage<UserTeacherDto> selectUserTeacherDtoById(@PathVariable Integer courseTeacherId) {
        PojoMessage<UserTeacherDto> msg = new PojoMessage<> ();
        UserTeacherDto data = service.selectUserTeacherDtoById (courseTeacherId);
        if (data != null) {
            msg.setCode (1);
            msg.setData (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有找到到教师信息");
        }
        return msg;
    }

    @ApiOperation("根据课程id->查询到”自己的“课程详细信息（课程类型信息+教师+用户+机构+课程信息 +章节信息+课时信息+评论列表）测试数据可用 8")
    @GetMapping("/CourseDetails/get/{courseId}")
    public PojoMessage<CourseDetailsDto> selectChapterLessonAll(@PathVariable Integer courseId, HttpServletRequest request) {
        PojoMessage<CourseDetailsDto> msg = new PojoMessage<> ();
        String token = request.getHeader ("token");
        if (token == null || token.equals ("")) {
            msg.setCode (-2);
            msg.setMsg ("未获取到用户信息；可能登录超时");
            return msg;
        }
        CourseDetailsDto data = service.selectCourseDetailsDtoSById (courseId, token);
        if (data != null) {
            msg.setCode (1);
            msg.setData (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有找到到课程详细信息");
        }
        return msg;
    }

    @ApiOperation("根据课程id->查询到自己的跟本课程相关的订单信息 若存在则返回 订单id 订单号")
    @GetMapping("/course/orders/get/{courseId}")
    public PojoMessage<Orders> selectOrdersByUserIdCourseId(@PathVariable Integer courseId, HttpServletRequest request) {
        PojoMessage<Orders> msg = new PojoMessage<> ();
        String token = request.getHeader ("token");
        if (token == null || token.equals ("")) {
            msg.setCode (-2);
            msg.setMsg ("未获取到用户信息；可能登录超时");
            return msg;
        }
        Orders data = service.selectOrdersByUserIdCourseId (courseId, token);
        if (data != null) {
            msg.setCode (1);
            msg.setData (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有找到查询到,自己的跟本课程相关的订单信息!");
        }
        return msg;
    }

    @ApiOperation("根据课时id 查询出课时信息")
    @GetMapping("/course/Lesson/get/{lessonId}")
    public PojoMessage<Lesson> selectLessonById(@PathVariable Integer lessonId) {
        PojoMessage<Lesson> msg = new PojoMessage<> ();
        Lesson data = service.selectLessonById (lessonId);
        if (data != null) {
            msg.setCode (1);
            msg.setData (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有课时信息!");
        }
        return msg;
    }
}

